import requests
import json


def sendMes(mesText):

    # Webhook的URL
    webhook_url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=486c9330-f6f9-4848-bed1-298e7639dd3d'

    # 要发送的数据
    data =  {
        "msgtype": "text",
        "text": {
            "content": mesText,
            # "mentioned_mobile_list":["18282968226"]
        }
    }

    # 将数据转换为JSON字符串（如果需要的话，通常requests的json参数可以自动处理）
    # json_data = json.dumps(data)  # 如果使用json参数，这行代码可以省略

    # 定义HTTP头部为字典（确保不是set）
    headers = {'Content-Type': 'application/json'}

    # 发送POST请求
    try:
        # 注意：如果data是字典，并且你想要发送JSON数据，应该使用json参数而不是data
        response = requests.post(webhook_url, json=data, headers=headers)

        # 检查响应状态码
        if response.status_code == 200:
            print('Message sent successfully!')
        else:
            print(f'Error sending message: {response.status_code} - {response.text}')

    except requests.RequestException as e:
        print(f'Error sending message: {e}')

# sendMes('好的刚哥，努力进化中！')

def sendPicMenu(picData,picMD5):
    # 企业微信机器人的Webhook URL
    WEBHOOK_URL = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=486c9330-f6f9-4848-bed1-298e7639dd3d'
    # 构造消息体
    data = {
        "msgtype": "image",
        "image": {
            "base64": picData,
            "md5": picMD5
        }
    }

    # 发送POST请求
    headers = {'Content-Type': 'application/json'}
    response = requests.post(WEBHOOK_URL, data=json.dumps(data), headers=headers)

    # 检查响应
    if response.status_code != 200:
        print(f'Request failed with status {response.status_code}: {response.text}')
    else:
        print('Message sent successfully!')

